#include "msg_q.hpp"
#include <unistd.h>


using std::cin;

int main()
{
    Serve server;
    pid_t  pid = fork();
    if(pid == 0)
    {
        // 子进程负责发送消息
        string memssage;
        while(1)
        {
            getline(cin, memssage);
            server.Send(memssage , 2);
            if(memssage == "quit")
                break;  
        }
        exit(0);
    }

    while(1)
    {
        string message;
        // 服务端负责收消息
        message = server.Recv(1);
        if(message.size() > 0)
        cout << "Client send  a message: " << message << endl;
        if(message == "quit")
            break;
    }
    return 0;
}
